package com.shujia.wyh.day29.test.codingtest;

public class SaleTicket implements Runnable{
    private int tickets = 100; //总票数
    private int count = 0;

    private Object obj = new Object();


    @Override
    public void run() {
        while (true){
            synchronized (obj){
                if(tickets>0){
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count++;
                    tickets--;
                    System.out.println(Thread.currentThread().getName()+"正在出售票号为"+count+"票");
                }
            }
        }
    }
}
